<?php

include _ITSTOCK_INCLUDE_DIR_.'html_search.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_message.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_navigation.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_links.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_menu.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_table_list.inc.php';

$_SESSION['on_delete']['software_location'] = $_SERVER['REQUEST_URI'];
$_SESSION['on_save']['software_location'] = $_SERVER['REQUEST_URI'];

$structure = itstock_html_search_init('software_location');
$structure['table_headers'] = array('N&deg;', 'Building', 'Department', 'Floor', 'Spot', 'Name', 'Case Label', '', '', '', '');
$structure['table_indexes'] = array('building', 'department', 'floor', 'spot', 'location', 'cpu');
$structure['table_actions'] = array(
  array( 'link' => 'main.php?page=hardware_location&id=%s', 'img' => 'img/location.png', 'title' => 'See Location', 'id' => 'cpu_location_id'),
  array( 'link' => 'main.php?page=hardware_cpu&id=%s', 'img' => 'img/hardware.png', 'title' => 'See Hardware', 'id' => 'id'),
  array( 'img' => 'img/edit.png', 'onclick' => 'itstock_page_request(\'add_software_location\', \'%s\')', 'title' => 'Edit', 'id' => 'id' ),
  array( 'link' => 'delete.php?type=software_location&id=%s', 'img' => 'img/delete.png', 'title' => 'Delete', 'id' => 'id')
);
$structure['table_error'] = 'Software hasn\'t been assigned yet.';

$Software = itstock_html_search_init('software');
if(isset($_GET['id'])) {
  $Software['where'][0] = 'software.id='.itstock_decode($_GET['id']);
  if(itstock_search_all($Software)){
    $structure['where'][0] = 'software_id='.$Software['data'][0]['id'];
  } else {
    $_SESSION['error'] = 'Please select a valid software.';
    header('Location: main.php?page=cpus');
    exit();
  }
} else {
  $_SESSION['error'] = 'Please select a software.';
  header('Location: main.php?page=software');
  exit();
}

$itstock_page_info['css'] = array('main.css', 'aside.css', 'float_menu.css', 'page.css', 'table.css', 'lightbox.css', 'form_save.css', 'table_info.css');
$itstock_page_info['js'] = array('common.js', 'ajax.js', 'request.js', 'lightbox.js', 'search.js', 'settings.js');
$itstock_page_info['title'] = 'Case Software - IT Stock Tool';
$itstock_page_info['menu_title'] = 'Case Software';
$itstock_page_info['menu_items'] = array(
  '<label onclick="itstock_page_request(\'add_software_location\', undefined,\'soft_id='.$_GET['id'].'\')">Assign to Case</label>'
);
$itstock_page_info['search_page'] = 'hardware_cpu';

itstock_html_base_header($itstock_page_info);
itstock_html_menu_search($itstock_page_info);
?>
  <table class="header">
    <tbody>
      <tr><th>Vendor:</th><td><?php echo itstock_get($Software, 'vendor'); ?></td><th>Serial:</th><td><?php echo itstock_get($Software, 'serialns'); ?></td></tr>
      <tr><th>Product:</th><td> <?php echo itstock_get($Software, 'product'); ?></td><th>Comment:</th><td rowspan="2"><?php echo itstock_get($Software, 'comment_software'); ?></td></tr>
      <tr><th>Version:</th><td><?php echo itstock_get($Software, 'version'); ?></td><th>&nbsp;</th></tr>
    </tbody>
  </table>
  <br><br><?php
echo '<table>';
itstock_html_table_list_data($structure, true, true, true);
echo '</table>';
itstock_html_base_footer();
?>
